package com.soda.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.soda.bean.Survey;
import com.soda.service.SurveyService;
import com.soda.service.impl.StudentServiceImpl;
import com.soda.service.impl.SurveyServiceImpl;

public class SurveyServlet extends HttpServlet {
	
		int surType;
		SurveyService ss=new SurveyServiceImpl();
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");

		String param = request.getParameter("param");// 获得参数，由参数判断执行方法
		if (param != null) {
			// 查看
			if ("selectgai".equals(param)) {

				selectgai(request, response);
			}
			if ("selectabout".equals(param)) {

				selectabout(request, response);
			}
			if ("selectcope".equals(param)) {

				selectcope(request, response);
			}
			//更改
			
			if ("update1".equals(param)) {

				update1(request, response);
			}
			if ("update2".equals(param)) {

				update2(request, response);
			}
			if ("update3".equals(param)) {

				update3(request, response);
			}
		}
	}
		

	
	


	private void update1(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		int types=Integer.parseInt(request.getParameter("Type"));
		String title=request.getParameter("titleName");
		String neirong=request.getParameter("neirong");
		int num=ss.update(types,title,neirong);
		if(num>0){
			selectgai(request, response);
		}else{
			System.out.println("更新失败！");
		}
		
	}
	private void update2(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		int types=Integer.parseInt(request.getParameter("Type"));
		String neirong=request.getParameter("neirong");
		int num=ss.update2(types,neirong);
		if(num>0){
			selectabout(request, response);
		}else{
			System.out.println("更新失败！");
		}
		
	}private void update3(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		int types=Integer.parseInt(request.getParameter("Type"));
		String neirong=request.getParameter("neirong");
		int num=ss.update2(types,neirong);
		if(num>0){
			selectcope(request, response);
		}else{
			System.out.println("更新失败！");
		}
		
	}

	private void selectcope(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		surType=3;
		Survey sv=ss.show(surType);
		request.setAttribute("survey", sv);
		try {
			request.getRequestDispatcher("houtai/pages/publicityManage/onePageManage/copyrightState.jsp").forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}




	private void selectabout(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		surType=2;
			Survey sv=ss.show(surType);
			request.setAttribute("survey", sv);
			System.out.println(surType);
			try {
				request.getRequestDispatcher("houtai/pages/publicityManage/onePageManage/concerningUs.jsp").forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}

	private void selectgai(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		surType=1;
			Survey sv=ss.show(surType);
			request.setAttribute("survey", sv);
			try {
				request.getRequestDispatcher("houtai/pages/publicityManage/synopsis.jsp").forward(request, response);
			} catch (ServletException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}




	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doGet(request, response);
	}

}
